<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="include/peizhi.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="${ctx}">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
        
        <title>后台管理中心</title> 
		<link rel="stylesheet" href="${ctx}/css/pintuer.css" /> 
		<link rel="stylesheet" href="${ctx}/css/admin.css" /> 
        <script type="text/javascript" src="${ctx}/js/jquery-1.9.1.min.js"></script>
    </head>
  	<body style="background-color:#f2f9fd;"> 
	  <jsp:include page="include/header.jsp" flush="true"/>
	  <!-- 编辑器插件 -->
	  <jsp:include page="../editor/jsp/editor.jsp" flush="true"></jsp:include>
  <div class="admin"> 
  	<div class="panel admin-panel">
	  <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> 单页信息</strong></div>
	  <div class="body-content">
	    <form method="post" id='formall' class="form-x" action="">   
	    <input type="hidden" name='reserve' value='1'>   
	      <div class="form-group">
	        <div class="label">
	          <label>标题：</label>
	        </div>
	        <div class="field">
	          <input type="text" id="title" class="input" name="title" value="" />
	          <div class="tips"></div>
	        </div>
	      </div>
	      <div class="form-group">
	        <div class="label">
	          <label>关键词：</label>
	        </div>
	        <div class="field">
	          <input type="text" class="input" name="keyword" value="" />
	          <div class="tips"></div>
	        </div>
	      </div>
	      <div class="form-group">
	        <div class="label">
	          <label>描述：</label>
	        </div>
	        <div class="field">
	          <textarea name="contents" cols="100" rows="8" style="width:700px;height:100px;"></textarea>
	          <div class="tips"></div>
	        </div>
	      </div>
	      <div class="form-group">
	        <div class="label">
	          <label>图片：</label>
	        </div>
	        <div class="field">
	           <input type="file" id='imageflle' class="input tips" style="width:25%; float:left;" value="选择图片"  />
	          <input type="button" class="button bg-blue margin-left" id="image1" value="+ 浏览上传"  style="float:left;">
	          <input type="hidden" id='headimg' name='headimg'  value="">
	          <div class="tipss">图片尺寸：500*200</div>
	          	<div id="imgt" style="float: left;margin-top: 3%;margin-left: -40%"></div>
	        </div>
	      </div>
	      <div class="form-group">
	        <div class="label">
	          <label>内容：</label>
	        </div>
	        <div class="field">
	          <!-- <textarea name="content"></textarea> -->
	          <textarea name="content" id="contents001" cols="100" rows="8" style="width:700px;height:200px;"></textarea>
	          <div class="tips"></div>
	        </div>
	      </div>
	      <div class="form-group">
	        <div class="label">
	          <label></label>
	        </div>
	        <div class="field">
	        <label>置顶：<input name="reserve1" type="radio" value="0" /> </label> 
	        <label>不置顶：<input name="reserve1" type="radio" value="1" checked="checked"/> </label>
	          <button class="button bg-main icon-check-square-o" id="formSub" type="button"> 提交</button>
	        </div>
	      </div>
	    </form>
	  </div>
	</div>
   <!-- <iframe scrolling="auto" rameborder="0" src="info.jsp" name="right" width="100%" height="100%"></iframe>  -->
  </div> 
 </body>
 <script type="text/javascript">
	$("#image1").click(function(){
		//上传图片
		var fd = new FormData();
			fd.append("upload", 1);
			fd.append("image", $("#imageflle").get(0).files[0]);//id为上传图片的id字符串image应该是后台接收的对象
		$.ajax({
				url: "${ctx}/Upload/image2",
				type: "POST",
				processData: false,
				contentType: false,//禁止ajax识别类型
				data: fd,
				success: function(data) {
					//console.log(d);
					//background:url(icon.jpg) no-repeat left center; width:200px; height:30px;
					if(data!='' && data!=null){
						$("#imgt").html("<img src='${ctx}/upload/img/"+data+"' width='100px' height='100px'>");
						$("#headimg").val(data);
						//$("#imagezhanshi").attr("style","background:url(${ctx}/upload/img/logo.jpg)no-repeat no-repeat center; width:200px; height:30px;");
					}else{
						alert("上传不成功请重新上传");
					}
				}
			});
		
	});
	function toSubmit(){
		if($("#title").val()=='' || $("#title").val()==null){
			alert("标题不可为空");
			return false;
		}
		return true;
	}
	$("#formSub").click(function(){
		if(toSubmit()){
			$.ajax({
				url:"${ctx}/activity/saveActivty",
				type:"post",
				data:$("#formall").serialize(),
				success:function(data){
					if(data=='0'){
						alert("保存成功");
					}else{
						alert("保存失败，请重试");
					}
				}
			});
		}
	});
</script>
</html>